# -*- coding:utf-8 -*-
#! python3

# FaceCat-Python
#Shanghai JuanJuanMao Information Technology Co., Ltd 

from facecat_objc import *

#点击单元格的方法
#grid 表格
#row 行
#column 列
#cell 单元格
#firstTouch:是否第一次触摸 
#firstPoint:第一次触摸的坐标 
#secondTouch:是否第二次触摸 
#secondPoint:第二次触摸的坐标
#clicks 点击次数
def onClickGridCell(grid, row, column, cell, firstTouch, firstPoint, secondTouch, secondPoint, clicks):
	print(cell.value)

gPaint = FCPaint() #创建绘图对象
gPaint.onClickGridCell = onClickGridCell

#加载示例
def loadUI():
	xml = """<?xml version="1.0" encoding="UTF-8"?>
	<html xmlns="facecat">
		<head>
		</head>
		<body>
			<div dock="fill" type="tab" selectedindex="0">
				<div name="TabPage" text="可视化生成" type="tabpage">
					<table name="Grid" text="Grid" location="50,59" size="331,235" headerheight="30">
						<tr>
							<th name="FCGridColumn" text="FCGridColumn"/>
							<th name="FCGridColumn2" text="FCGridColumn2"/>
							<th name="FCGridColumn3" text="FCGridColumn3"/>
						</tr>
						<tr>
							<td>cell1</td>
							<td>cell2</td>
							<td>cell3</td>
						</tr>
						<tr>
							<td>cell1</td>
							<td>cell2</td>
							<td>cell3</td>
						</tr>
					</table>
				</div>
				<div name="TabPage2" text="代码创建" type="tabpage"/>
			</div>
		</body>
	</html>
	"""
	renderFaceCat(gPaint, xml)
	grid = findViewByName("Grid", gPaint.views)
	for i in range(0,100):
		row = FCGridRow()
		grid.rows.append(row)
		for j in range(0,3):
			cell = FCGridCell()
			row.cells.append(cell)
			if j == 0:
				checkBox = FCCheckBox()
				addViewToGridCell(checkBox, cell, grid)
			else:
				cell.value = "Cell"
	invalidate(gPaint)

class AppDelegate(NSObject):
	def windowWillClose_(self, notification):
		os._exit(0)
	def applicationDidFinishLaunching_(self, notification):
		gPaint.size = FCSize(900, 770)
		window = NSWindow.alloc().initWithContentRect_styleMask_backing_defer_(
		NSMakeRect(0, 0, gPaint.size.cx, gPaint.size.cy),
		15,
		NSBackingStoreBuffered,
		False
		)
		window.setDelegate_(self)
		window.orderFrontRegardless()
		view = FCUIView.alloc().initWithFrame_(NSMakeRect(0, 0, gPaint.size.cx, gPaint.size.cy))
		view.paint = gPaint
		window.setContentView_(view)
		gPaint.view = view
		loadUI()

app = NSApplication.sharedApplication()
delegate = AppDelegate.alloc().init()
app.setDelegate_(delegate)
app.run()
